var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:27017/conFusion';

// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
    assert.equal(err, null);
    console.log("Connected correctly to server");

    var collection = db.collection("dishes");
    collection.insertOne({ name: "tancolo", description: "test" }, function(err, result) {
        assert.equal(err, null);
        console.log('After insertOne:');
        console.log(result.ops);

        collection.find({}).toArray(function(err, docs) {
            assert.equal(err, null);
            console.log("Found!");
            console.info(docs);;

            //close the collection
            db.dropCollection("dishes", function(err, result) {
                assert.equal(err, null);
                db.close();
            });
        });

    });
});